var tableImportSelect = "";
layui.use(['table', 'form', 'util'], function () {
    var table = layui.table;
    var util = layui.util;
    var form = layui.form;

    //渲染表格
    var importTbIns = table.render({
        elem: '#importTable',
        url: prefix + '/db/list',
        page: {
            limit: 1000
        },
        height: "full-90",
        toolbar: false,
        cols: [
            [
                {type: 'checkbox'},
                {type: 'numbers'},
                {field: 'table_name', title: '表名称', sort: true},
                {field: 'table_comment', title: '表描述', sort: true},
                {
                    field: 'create_time', title: '创建时间', align: 'center', sort: true, templet: function (d) {
                        return dateDisplay(util, d.create_time);
                    }
                },
                {
                    field: 'update_time', title: '更新时间', align: 'center', sort: true, templet: function (d) {
                        return dateDisplay(util, d.update_time);
                    }
                }
            ]
        ]
    });

    //表格搜索
    form.on('submit(importTbSearch)', function (data) {
        importTbIns.reload({where: data.field, page: {curr: 1}});
        return false;
    });

    //触发排序事件
    table.on('sort(importTable)', function (obj) {
        importTbIns.reload({
            initSort: obj
            , where: {
                fieldName: obj.field
                , sortType: obj.type
            }
        });
    });

    //监听勾选
    table.on('checkbox(importTable)', function (obj) {
        var checkStatus = table.checkStatus('importTable');
        var dataList = checkStatus.data;

        var tableNames = dataList.map(function (item) {
            return item.table_name;
        });
        tableImportSelect = tableNames.join(",");
    });

});